package com.gxaedu.rbac.interceptor;

import com.gxaedu.rbac.pojo.User;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author:Teacher黄
 * @date:Created at 2020/04/21
 */
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        // 判断是否登陆了
        User user = (User) request.getSession().getAttribute("user");
        if(user == null){
            // 说明没有登陆
            // 没有登陆重定向到登陆页面
            response.sendRedirect("/login/page");
            return false;
        }
        // 放行
        return true;
    }
}
